package com.huopaolan.yohuoshop.Mvp.View.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.huopaolan.yohuoshop.Adapter.ViewPagerAdapter.SlidingMenuAdapter;
import com.huopaolan.yohuoshop.Mvp.View.Activity.HomeActivity;
import com.huopaolan.yohuoshop.R;

public class SlidingMenuFragment extends Fragment {
    private RecyclerView recyclerView;
    private SlidingMenuAdapter slidingMenuAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_slidingmenu, container, false);
        initView(inflate);
        return inflate;
    }

    @Override
    public void onStart() {
        Window window = getActivity().getWindow();
        window.setStatusBarColor(Color.BLACK);
        super.onStart();
    }

    private void initView(View inflate) {
        if (HomeActivity.menuEntity.values == null) {
            return;
        }
        recyclerView = inflate.findViewById(R.id.home_menu_recycler);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        slidingMenuAdapter = new SlidingMenuAdapter(R.layout.item_home_menu);
        recyclerView.setLayoutManager(layoutManager);
        slidingMenuAdapter.addData(HomeActivity.menuEntity.values);
        recyclerView.setAdapter(slidingMenuAdapter);
        slidingMenuAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Toast.makeText(getActivity(), "点击" + (position + 1), Toast.LENGTH_SHORT).show();
                HomeActivity.slidingMenu.showContent();
            }
        });
    }
}
